package co.edu.usbcali.ai.ga;

import co.edu.usbcali.ai.ga.samples.hello.HelloBreed;

import com.cgarias.utils.Random;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
//		int[][] paramRange={{20,5,50},{32,25,90}};
		int[][] paramRange={{20,20,80},{32,25,85}};
		int[][][] results=new int [paramRange[1][0]-paramRange[0][0]]
		                      [paramRange[1][1]-paramRange[0][1]]
		                      [paramRange[1][2]-paramRange[0][2]];
		float stop=5;
		int cromosomSize=5;
		
		for (int i = paramRange[0][0]; i <= paramRange[1][0]; i++) {
			int generationSize=i;
			int minSurvivors=(int)(i*paramRange[0][1]/100);
			int maxSurvivors=(int)(i*paramRange[1][1]/100);
//			for (int j = paramRange[0][1]; j < paramRange[1][1]; j++) {
			for (int j = minSurvivors; j <= maxSurvivors; j++) {
				int minWinners=Math.max((int)((j*paramRange[0][2]/100)),1);
				int maxWinners=(j*paramRange[1][2]/100);
				for (int k = minWinners; k <= maxWinners; k++) {
//					int winners=Math.max((int)((i*j/100)*(k/100)),1);
//					int mutateds=Math.max((int)((i*j/100)*((100-k)/100)),1);
					int winners=k;
					int mutateds=j-k;
					int children=generationSize-winners-mutateds;
					
					Breed race=new HelloBreed(cromosomSize);	
//					Race race=new BinaryRace(new BinaryCromosomType(cromosomSize),SimpleCromosom.class);	
					Ga ga=new Ga(race,generationSize,winners,children,mutateds);
					ga.addActionListener(new TaskListener());
					ga.setStopValue(stop);
					ga.run();
					try {
						ga.join();
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
//					results[i-paramRange[0][0]][j-paramRange[0][1]][k-paramRange[0][2]]=ga.getTotalIndividuals();
					System.out.println("Tamaño generación:"+i+" hijos:"+children+" ganadores:"+winners+" mutados:"+mutateds);
				}
			}
			
		}
		/*
		for (int a = 0; a < results.length; a++) {
			for (int b = 0; b < results.length; b++) {
				for (int c = 0; c < results.length; c++) {
					int population=a+paramRange[0][0];
					int hijos=(int)((b+paramRange[0][1])/100);
					int winners=(int)(hijos*((c+paramRange[0][2])/100));
					int mutateds=(int)(hijos*((100-c-paramRange[0][2])/100));
					System.out.println("Tamaño generación:"+population+" hijos:"+hijos+" ganadores:"+winners+" mutados:"+mutateds);					
				}
			}
		}
		*/

	}

}
